import request from '@/utils/request'

enum API {
  GetOrderIndex = '/agent/newPayment/GrabOrderIndex',
  GetReportIndex = '/agent/report/index',
  GetPaymentCode = '/agent/paymentCode/index',
  AddReport = '/agent/report/add',
  EditReport = '/agent/report/edit',
  DelReport = '/agent/report/del',
  GrabPayment = '/agent/newPayment/GrabOrderAgent',
  ReviewOrder = '/agent/reviewOrder/index',
  GetOrderStatus = '/agent/newPayment/OrderStatus',
  CancelOrder = '/agent/reviewOrder/GrabOrderCancel',
  ReportOrder = '/agent/reviewOrder/reporting',
  RemittanceOrder = '/agent/reviewOrder/remittance',
  AgentStatus = '/agent/reviewOrder/AgentStatus',
  Transfer = '/agent/reviewOrder/transfer'
}

export function TransferApi(orderNo: string, username: string) {
  return request({
    url: API.Transfer,
    method: 'post',
    data: {
      orderNo,
      username
    }
  })
}

export function AgentStatusApi(username: string) {
  return request.post(
    API.AgentStatus,
    {
      username
    },
    {
      showError: false
    }
  )
}

export function RemittanceOrderApi(
  orderNo: string,
  agentImgSrc: Array<string>,
  agentRemark?: string
) {
  return request.post(API.RemittanceOrder, {
    orderNo,
    agentImgSrc,
    agentRemark
  })
}

export function ReportOrderApi(orderNo: string, review: string | number) {
  return request.post(API.ReportOrder, { orderNo, review })
}

export function CancelOrderApi(orderNo: string) {
  return request({
    url: API.CancelOrder,
    method: 'post',
    data: {
      orderNo
    }
  })
}

export async function GetOrderStatusApi() {
  return request({
    url: API.GetOrderStatus,
    method: 'post'
  })
}

export function ReviewOrderApi(data: {
  page: number
  limit: number
  settlement?: number | string
  payStatus?: number | string
  orderStatus?: number | string
}) {
  return request({
    url: API.ReviewOrder,
    method: 'post',
    data
  })
}

export function GrabPaymentApi(data: { orderNo: string; review: string }) {
  return request({
    url: API.GrabPayment,
    method: 'post',
    data
  })
}

export function DelReportApi(data: { id: string }) {
  return request({
    url: API.DelReport,
    method: 'delete',
    data: {
      ids: [data.id]
    }
  })
}

export function EditReportApi(data: any) {
  return request({
    url: API.EditReport,
    method: 'post',
    data
  })
}

export function AddReportApi(data: any) {
  return request({
    url: API.AddReport,
    method: 'post',
    data
  })
}

export function GetPaymentCodeApi(data: { page: number; limit: number }) {
  return request({
    url: API.GetPaymentCode + `?page=${data.page}&limit=${data.limit}`,
    method: 'post',
    data
  })
}

export function GetReportIndexApi(data: { page: number; limit: number; reviewStatus?: number }) {
  return request({
    url: API.GetReportIndex + `?page=${data.page}&limit=${data.limit}`,
    method: 'post',
    data
  })
}

export function GetOrderIndexApi(data: { page: number; limit: number; orderStatus?: number }) {
  return request({
    url: API.GetOrderIndex + `?page=${data.page}&limit=${data.limit}`,
    method: 'post',
    data
  })
}
